import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		int[][] a=new int[10000][101];
		int m,n,k;
		char s;
		Mayi mayi=new Mayi();
		Scanner cin=new Scanner(System.in);
		m=cin.nextInt();
		n=cin.nextInt();
		for(int i=0;i<m;i++) {
			for(int j=0;j<n;j++) {
				a[i][j]=cin.nextInt();
			}
		}
		mayi.x=cin.nextInt();
		mayi.y=cin.nextInt();
		s=cin.next().charAt(0);
		switch (s) {
		case 'U':
			mayi.s=0;
			break;
		case 'R':
			mayi.s=1;
			break;
		case 'D':
			mayi.s=2;
			break;
		case 'L':
			mayi.s=3;
			break;
		}
		k=cin.nextInt();
		for(int i=0;i<k;i++) {
			if(a[mayi.x][mayi.y]==1) {
				mayi.s=(++mayi.s)%4;
				a[mayi.x][mayi.y]=0;
				switch (mayi.s) {
				case 0:
					if(mayi.x>0)
					mayi.x--;
					break;
				case 1:
					if(mayi.y<n)
					mayi.y++;
					break;
				case 2:
					if(mayi.x<m)
					mayi.x++;
					break;
				case 3:
					if(mayi.y>0)
					mayi.y--;
					break;
				}
			}else {
				mayi.s--;
				if(s<0)
					s=3;
				a[mayi.x][mayi.y]=1;
				
				switch (mayi.s) {
				case 0:
					if(mayi.x>0)
					mayi.x--;
					break;
				case 1:
					if(mayi.y<n)
					mayi.y++;
					break;
				case 2:
					if(mayi.x<m)
					mayi.x++;
					break;
				case 3:
					if(mayi.y>0)
					mayi.y--;
					break;
				}
			}
		}
		cin.close();
		System.out.println(mayi.x+"  "+mayi.y);
	}
}

class Mayi{
	int x;
	int y;
	int s; //0:U,1:R,2:D,3:L
}
